package com.biyao.controller.base;


import com.baomidou.mybatisplus.plugins.Page;
import com.biyao.schedulingcommon.response.BaseMsg;
import com.biyao.schedulingcommon.response.FailureMsg;
import com.biyao.schedulingcommon.response.SuccessMsg;
import com.biyao.schedulingentity.base.TRollerMaterialEntity;
import com.biyao.service.model.base.imp.TRollerMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * 
 *
 * @author code generator
 * @date 2019-09-16 09:44:10
 */
@Api(tags = {"轧辊材质表"})
@RestController
@RequestMapping("api/v1/trollermaterial")
public class TRollerMaterialController {

    @Autowired
    private TRollerMaterialService tRollerMaterialService;



    @ApiOperation(value = "列表")
    @GetMapping
    public BaseMsg list(@RequestParam(defaultValue = "1") Integer pageNum,
                        @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        Page page = tRollerMaterialService.list(pageNum, pageSize);

        return new SuccessMsg(page);
    }




     @ApiOperation(value = "详情")
     @GetMapping("/info/{id}")
    public BaseMsg info(@PathVariable("id") Integer id) {
            TRollerMaterialEntity tRollerMaterial = tRollerMaterialService.selectById(id);

        return new SuccessMsg(tRollerMaterial);
    }



    @ApiOperation(value = "保存")
    @PostMapping
    public BaseMsg save(@RequestBody TRollerMaterialEntity tRollerMaterial) {
        if(tRollerMaterialService.selectCodeIsRepeat(tRollerMaterial.getCode())){
            return new FailureMsg(500,"代号重复");
        } else {
             tRollerMaterialService.insert(tRollerMaterial);
             return new SuccessMsg();
        }
    }



    @ApiOperation(value = "更新")
    @PutMapping
    public BaseMsg update(@RequestBody TRollerMaterialEntity tRollerMaterial) {
        if(tRollerMaterialService.selectUpdateCodeIsRepeat(tRollerMaterial.getCode(),tRollerMaterial.getId())){
            return new FailureMsg(500,"代号重复");
        }
        tRollerMaterialService.updateAllColumnById(tRollerMaterial);

        return new SuccessMsg();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("delete/{id}")
    public BaseMsg delete(@PathVariable("id") Integer id) {
        tRollerMaterialService.deleteById(id);
        return new SuccessMsg();
    }


}
